﻿using System.Collections.Generic;
using System.Threading.Tasks;
using Red.Controls.Diagrams;
using Red.Controls.Diagrams.Declarators;
using Red.Controls.ViewModels;
using Red.Core.Containers;

namespace Red.Toolkit.NodeDeclaratorEditor
{
    public class DummyDropDataItem : DataItem
    {
        #region Data

        private readonly NodeDropDeclarator _drop;
        private readonly bool _isInherited;

        #endregion Data

        #region C-tor

        public DummyDropDataItem( DataItem parent, NodeDropDeclarator drop, int id, bool isInherited )
            : base( parent )
        {
            _drop = drop;
            Title = isInherited ? $"[{id}] ( inherited )" : $"[{id}]";
            _isInherited = isInherited;
            IsExpanded = true;
        }

        #endregion C-tor

        #region DataItem implementation

        public override string Type => "Drop";

        public override string Value
        {
            get { return ""; }
            set { }
        }

        public override DataItemKind Kind => DataItemKind.Compound;

        protected override Task EnumerateChildrenAsync( IRangedCollection<DataItem> children )
        {
            children.Clear();

            // each drop has only two properties: Class and Binding
            children.Add( new DummyDropPropertyDataItem( this, _drop, "Class", _isInherited ) );
            children.Add( new DummyDropPropertyDataItem( this, _drop, "Binding", _isInherited ) );

            // inherited drops cannot be deleted
            if ( !_isInherited )
                children.Add( new DataButtonItemBase( this, "Remove drop", NodeControlCommands.DeleteDrop, _drop ) );

            return Task.CompletedTask;
        }

        #endregion DataItem implementation
    }
}
